/************************************************************************/
/*Copyright (c) James Zhao 2007,2008
/*This file is part of AdminOverlay.
/*AdminOverlay is free software: you can redistribute it and/or modify
/*it under the terms of the GNU General Public License as published by
/*the Free Software Foundation, either version 3 of the License, or
/*(at your option) any later version.
/*
/*AdminOverlay is distributed in the hope that it will be useful,
/*but WITHOUT ANY WARRANTY; without even the implied warranty of
/*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/*GNU General Public License for more details.
/*
/*You should have received a copy of the GNU General Public License
/*along with Foobar.  If not, see <http://www.gnu.org/licenses/>.                                                                     */
/*************************************************************************/
#include "DockedPanel.h"
#include "UIManager.h"

DockedPanel::DockedPanel(void) : UIPanel(0,0,0,0)
{
	TopColor(0xC2464F42);
	BottomColor(0xC2464F42);
	Height(300);
	cachedHeight = -1;
	isMouseDown = false;
	connect(this, SIGNAL(mouseDown(QPoint,bool)), SLOT(onMouseDown(QPoint, bool)), Qt::DirectConnection);
	connect(this, SIGNAL(mouseMoved(QPoint,bool,bool)), SLOT(onMouseMove(QPoint,bool,bool)), Qt::DirectConnection);
	connect(this, SIGNAL(mouseUp(QPoint,bool)), SLOT(onMouseUp(QPoint, bool)), Qt::DirectConnection);
}


DockedPanel::~DockedPanel(void)
{
}

void DockedPanel::layout( QPoint offset )
{
	if(cachedHeight != UIManager::currentInstance()->Height())
	{
		Y(UIManager::currentInstance()->Height() - Height());
		cachedHeight = UIManager::currentInstance()->Height();
	}
	X(0);
	Width(UIManager::currentInstance()->Width());
	UIPanel::layout(offset);
}

void DockedPanel::onMouseDown( QPoint point, bool isPrimaryTarget )
{
	originalY = point.y();
	isMouseDown = true;
}

void DockedPanel::onMouseMove( QPoint point, bool pIsMouseDown , bool isPrimaryTarget)
{
	if(isMouseDown)
	{						
		Y(Y() + (point.y() - originalY));
		Height(Height() - (point.y() - originalY));
	}
}

void DockedPanel::onMouseUp( QPoint point , bool isPrimaryTarget)
{
	originalY = 0;
	isMouseDown = false;
}